package org.NooLab.itexx.app.gui.handlers;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JWindow;

import org.NooLab.itexx.app.gui.definition.ITexxWindowGui2;




public class GlassPaneCover extends JWindow{

	ITexxWindowGui2 windowGui ;
	
	JWindow coverwindow ;

	private JFrame mainFrame;

	float transparency = 0.5f;
	
	public GlassPaneCover(ITexxWindowGui2 gui, int flag) {
		// 

		windowGui = gui;

		mainFrame = windowGui.getMainFrame() ;
		createPane();
		
		setAlwaysOnTop(true);
		
	}
	
	@Override
	public void paint(Graphics g){
		
		
		setBackground(new Color(0.9f,0.9f,0.9f,0.5f));
		
		Graphics2D g2 = (Graphics2D) g.create();
		g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transparency)); 

		super.paint(g2);  

	}

	

	private void createPane() {
		// 
		
		coverwindow = new JWindow();

		coverwindow.setVisible(false);
		coverwindow.setSize(1, 1);
		coverwindow.setLocation( mainFrame.getLocation().x, mainFrame.getLocation().y);

		Dimension d = mainFrame.getSize();
		coverwindow.setSize(d) ;
		
		Container rootpane = coverwindow.getContentPane();
		JPanel topPanel ;
		
		
		coverwindow.getContentPane().setBackground( new Color(0.94f,0.94f,0.98f,0.51f));
		coverwindow.setBackground( new Color(0.94f,0.94f,0.98f,0.51f));
		
		
		
		topPanel = new JPanel();
		
		
		
		Component[] wwc = coverwindow.getRootPane().getComponents();

		for (int i=0;i<wwc.length;i++){
			
			String cn = wwc[i].getClass().getSimpleName().toLowerCase();
			
			if ((wwc[i] instanceof JPanel) || (cn.contains("jpanel"))){
				topPanel = (JPanel)wwc[i]; 
				topPanel.setOpaque(true);
				topPanel.setBackground( new Color(0.94f,0.94f,0.98f,0.51f)); break;
			}
		}

		coverwindow.setGlassPane(topPanel) ;
		
		coverwindow.setVisible(true);
	}

}
